<?php
declare (strict_types = 1);

namespace app\adminapi\controller\system;

use adminmatrix\admin\BaseController;
use adminmatrix\admin\service\JsonService;
use app\adminapi\logic\system\PermissionLogic;
use think\Request;
use think\response\Json;
use hg\apidoc\annotation as Apidoc;

#[
    Apidoc\Title("权限管理"),
    Apidoc\Group("system"),
]
class PermissionController extends BaseController
{

    #[
        Apidoc\Title("权限列表")
    ]
    public function lists(Request $request): Json
    {
        return $this->dataLists();
    }

    #[
        Apidoc\Title("新增菜单"),
        Apidoc\Method("POST")
    ]
   public function save(Request $request , PermissionLogic $logic)  : Json
   {
       try {
            $logic->save($request);
            return JsonService::success('新增菜单成功');
       } catch (\Exception $e)
       {
           return JsonService::fail($e->getMessage() , $e->getCode());
       }
   }

    #[
        Apidoc\Title("编辑菜单"),
        Apidoc\Method("PUT")
    ]
   public function update(Request $request , PermissionLogic $logic) :Json
   {
       try {
           $logic->update($request);
           return JsonService::success('修改菜单成功');
       } catch (\Exception $e)
       {
           return JsonService::fail($e->getMessage() , $e->getCode());
       }
   }

    #[
        Apidoc\Title("删除菜单"),
        Apidoc\Method("DELETE")
    ]
   public function delete(Request $request , PermissionLogic $logic) : Json
   {
       try {
           $logic->delete($request);
           return JsonService::success('删除菜单成功');
       } catch (\Exception $e)
       {
           return JsonService::fail($e->getMessage() , $e->getCode());
       }
   }
}
